<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="gdca.webservice.common.ResponseInfo"%>
<html>
	<head>
		<OBJECT ID='GDCACom'
			CLASSID='clsid:6DD195B3-1B23-468A-9049-C29CFCDB4FE2' width='0'
			height='0'></OBJECT>
	</head>
	<script src="/tyst-demo/gdca/js/PkiOper.js"></script>
	<script src="/tyst-demo/gdca/js/util.js"></script>
	<body>
		<script>
		<%
		try{
		System.out.println("进入写KEY页面");
		boolean startWriteKeyFlag = false;
		ResponseInfo responseInfo = (ResponseInfo) request.getAttribute("responseInfo");
		if(responseInfo==null)
		{
		    System.out.println("responseInfo对象为空");
		%>
			alert("responseInfo对象为空");
		<%
		}else if(responseInfo.getIsSuccess()==null  || !responseInfo.getIsSuccess().equals("0"))
		{
		%>
			alert("responseInfo对象里的成功标志为：<%=responseInfo.getIsSuccess()%>。表示失败。0才表示成功");
		<%
		}else 
		{
			System.out.println("准备写KEY参数");
			//签名证书
			String signCert = responseInfo.getSignCert();
			if(signCert==null)
			{
				signCert="";
			}
			else
			{
				signCert = signCert.replaceAll("\r","").replaceAll("\n","");
			}
			//加密证书
			String encCert = responseInfo.getEncCert();
			if(encCert==null)
			{
				encCert="";
			}
			else
			{
				encCert = encCert.replaceAll("\r","").replaceAll("\n","");
			}
			//数字信封
			String cryptPrivKey = responseInfo.getCryptPrivKey();
			if(cryptPrivKey==null)
			{
				cryptPrivKey="";
			}
			else
			{
				cryptPrivKey = cryptPrivKey.replaceAll("\r","").replaceAll("\n","");
			}
			//加密序列号
			String encSn = responseInfo.getEncSn();
			if(encSn==null)
			{
				encSn="";
			}
			else
			{
				encSn = encSn.replaceAll("\r","").replaceAll("\n","");
			}
			//签名序列号
			String signSn = responseInfo.getSignSn();
			if(signSn==null)
			{
				signSn="";
			}
			else
			{
				signSn = signSn.replaceAll("\r","").replaceAll("\n","");
			}
			//ca证书
			String caCert = responseInfo.getCaCert();
			if(caCert==null)
			{
				caCert="";
			}
			else
			{
				caCert = caCert.replaceAll("\r","").replaceAll("\n","");
			}
			//keyid
			String keyId = responseInfo.getKeyId();	
			if(keyId==null)
			{
				keyId="";
			}
			else
			{
				keyId = keyId.replaceAll("\r","").replaceAll("\n","");
			}
			//超级PIN码
			String initPassword = responseInfo.getInitPassword();	
			if(initPassword==null)
			{
				initPassword="";
			}
			else
			{
				initPassword = initPassword.replaceAll("\r","").replaceAll("\n","");
			}
	
			String 	isBack = (String)request.getAttribute("i_isBack");
			System.out.println("准备写KEY参数，完毕");		
			String i_oldPin = "123456";
			String i_newPin = "123456";
			String 	busyType = (String)request.getAttribute("busyType");
			System.out.println("业务类型编号" + busyType);
			if(busyType.equals("003"))
			{
				//注销
				%>
				alert("注销成功");
				<%
			}else if(busyType.equals("006"))
			{
				//解锁
				%>
				var ret = GDCAUnlockKey(GDCACom,"<%=initPassword%>", "<%=i_newPin%>");
				if(ret==0)
				{
					alert("解锁成功");
				}
				else
				{
					alert("解锁失败");
				}
				<%
			}else
			{
				startWriteKeyFlag = true;
				if(startWriteKeyFlag)
				{
				%>
					//alert("isBack=" + "<%=isBack%>");
					//alert("signCert=" + "<%=signCert%>");
					//alert("signSn=" + "<%=signSn%>");
					//alert("encCert=" + "<%=encCert%>");
					//alert("encSn=" + "<%=encSn%>");
					//alert("cryptPrivKey=" + "<%=cryptPrivKey%>");
					//alert("i_oldPin=" + "<%=i_oldPin%>");
					//alert("i_newPin=" + "<%=i_newPin%>");
					//alert("caCert=" + "<%=caCert%>");
					//alert("keyId=" + "<%=keyId%>");
					var ret = GDCATystCertDownLoadWrite(
				        GDCACom,
				        "<%=isBack%>", // 更新标志Y
						"<%=signCert%>", 
						"<%=signSn%>", 
						"<%=encCert%>",
						"<%=encSn%>", 
						"<%=cryptPrivKey%>", // 数字信封
						"<%=i_oldPin%>", 
						"<%=i_newPin%>", 
						"<%=caCert%>",
						"<%=keyId%>"
						); 
					if(ret!=0)
					{
						alert("操作失败");
					}
					else
					{
						alert("操作成功");
					}				
			  <%}
		  }
		}
		}catch(Exception e)
		{
			System.out.println("出现异常");
		%>
			alert("操作异常");
			return false;
		<%
			e.printStackTrace();
		}
		finally
		{
		%>
			parent.closediv();
		<%
		}
		%>
	</script>

	</body>
	<script>	
	</script>
</html>
